<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <meta name="renderer" content="webkit">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-cache">
    <meta http-equiv="Expires" content="0">
    <title>违规的商品</title>
    <link rel="stylesheet" href="../../css/normalize.min.css">
    <link rel="stylesheet" href="../../css/common.css">
    <link rel="stylesheet" href="../../css/bootstrap.cosmo.css">
    <link rel="stylesheet" href="../../plugin/bootstrap-datetimepicker/css/bootstrap-datetimepicker.css">
    <!-- <link rel="stylesheet" href="https://bootswatch.com/3/united/bootstrap.min.css"> -->
    <!-- <link rel="stylesheet" href="https://bootswatch.com/3/flatly/bootstrap.min.css"> -->
    <link rel="stylesheet" href="../../plugin/icheck/skins/all.css">
    <link rel="stylesheet" href="../../plugin/icheck/skins/flat/flat.css">
    <style media="screen">
        .form-group {
            margin-bottom: 0;
        }

        body {
            padding-bottom: 80px;
        }

        #productList tbody td,
        #productList thead tr {
            vertical-align: middle;
        }

        td div p {
            margin: 0;
        }
    </style>
</head>

<body>
    <div class="configNav"></div>

    <div class="container-fluid">
        <div class="row">
            <!--leftcontent start-->
            <div class="col-md-2">
                <div class="list-group">
                    <a href="./com_release.html" class="list-group-item">商品发布</a>
                    <a href="./com_insale.html" class="list-group-item">出售中的商品</a>
                    <a href="./com_warehouse.html" class="list-group-item active">仓库中的商品</a>
                    <a href="./com_picspace.html" class="list-group-item">图片空间</a>
                </div>
            </div>
            <!--leftcontent end-->

            <!--rightcontent start-->
            <div class="col-md-10">
                <ol class="breadcrumb">
                    <li><a href="javascript:void(0)">商家管理中心</a></li>
                    <li><a href="javascript:void(0)">商品</a></li>
                    <li class="active">仓库中的商品</li>
                </ol>
                <ul class="nav nav-tabs">
                    <li role="presentation"><a href="./com_warehouse.html">仓库中的商品</a></li>
                    <li role="presentation" class="active"><a href="./com_gool.html">违规的商品</a></li>
                    <li role="presentation"><a href="./com_waitingAudit.html">等待审核的商品</a></li>
                </ul>
                <form class="form-inline text-right" style="margin:10px 0;">
                    <div class="form-group">
                        <label for="exampleInputName2">本店分类</label>&nbsp;&nbsp;
                        <select class="form-control" id="gcIdSel">

                        </select>
                    </div>&nbsp;&nbsp;
                    <div class="form-group">
                        <!-- <label for="exampleInputEmail2">Email</label> -->
                        <select class="form-control" id="goodsNameSel">
                            <option>请选择搜索类型</option>
                            <option>商品名称</option>
                            <option>平台货号</option>
                            <option>商品货号</option>
                        </select>
                    </div>&nbsp;&nbsp;
                    <div class="form-group">
                        <!-- <label for="exampleInputEmail1">Email address</label> -->
                        <input type="email" class="form-control" id="inputStr" placeholder="">
                    </div>&nbsp;&nbsp;
                    <button type="button" class="btn btn-default" id="btnSearch">搜索</button>
                </form>
                <table class="table" id="productList">
                    <thead>
                        <tr>

                            <th class="text-center">商品名称</th>
                            <th class="text-center">违规禁售原因</th>
                            <th class="text-center">价格</th>
                            <th class="text-center">库存</th>
                            <th class="text-center">操作</th>
                        </tr>
                        <tr>
                            <th>
                                <input type="checkbox" class="deleteCtrl" value="option1" aria-label="...">&nbsp;&nbsp;
                                <button class="btn btn-default btn-sm btnDel" type="submit"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span>&nbsp;&nbsp;删除</button>&nbsp;&nbsp;
                                <!-- <button class="btn btn-default btn-sm" type="submit"><span class="glyphicon glyphicon-share" aria-hidden="true"></span>&nbsp;&nbsp;下架</button> -->
                            </th>
                            <th class="text-center"></th>
                            <th class="text-center"></th>
                            <th class="text-center"></th>
                            <th class="text-center"></th>
                        </tr>
                    </thead>
                    <tbody>

                    </tbody>
                    <tfoot>
                        <tr>
                            <th>
                                <input type="checkbox" class="deleteCtrl" value="option1" aria-label="...">&nbsp;&nbsp;
                                <button class="btn btn-default btn-sm" type="submit"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span>&nbsp;&nbsp;删除</button>&nbsp;&nbsp;
                                <!-- <button class="btn btn-default btn-sm" type="submit"><span class="glyphicon glyphicon-share" aria-hidden="true"></span>&nbsp;&nbsp;下架</button> -->
                            </th>
                            <th class="text-center"></th>
                            <th class="text-center"></th>
                            <th class="text-center"></th>
                            <th class="text-center"></th>
                        </tr>
                    </tfoot>
                </table>
                <!-- 分页 -->
                <nav aria-label="...">
                    <div class="">
                        <span id="pageNum">共&nbsp;<strong></strong>&nbsp;页&nbsp;/&nbsp;</span><span id="totalNum">&nbsp;<strong>0</strong>&nbsp;条数据</span>
                    </div>
                    <ul id="example"></ul>
                </nav>
            </div>
            <!--rightcontent end-->
        </div>
        <!-- row end -->
    </div>
    <!-- container end -->

    <script src="../../js/jquery.min.js" charset="utf-8"></script>
    <script src="../../js/common.js" charset="utf-8"></script>
    <script src="../../js/nav.js" charset="utf-8"></script>
    <script src="../../js/bootstrap.min.js" charset="utf-8"></script>
    <script src="../../plugin/bootstrap-datetimepicker/js/bootstrap-datetimepicker.js" charset="utf-8"></script>
    <script src="../../plugin/bootstrap-datetimepicker/js/bootstrap-datetimepicker.zh-CN.js" charset="utf-8"></script>
    <script src="../../plugin/wangEditor/release/wangEditor.min.js" charset="utf-8"></script>
    <!-- <script src="../js/com_release.js" charset="utf-8"></script> -->
    <script src="../../plugin/icheck/icheck.min.js" charset="utf-8"></script>
    <script src="../../plugin/layer/layer.js" charset="utf-8"></script>
    <script src="../../js/ajax.js" charset="utf-8"></script>
    <script type="text/javascript" src="../../js/bootstrap-paginator.js"></script>
    <script type="text/javascript">
        $('input').iCheck({
            checkboxClass: 'icheckbox_flat-red',
            radioClass: 'iradio_flat-red'
        });

        //列表渲染
        var pageUrls = serverURL + '/goods/getBusinessGoodsList';
        var chosenList = '';
        //初始化当前页//
        var page = 1;

        //一页的条数
        var pagesize = 10;
        $(document).ready(function() {
            pageInit();
        });
        //列表显示
        function pageInit() {
            var gcId1Val;
            if($('#gcIdSel option:selected').index() == 0){
                gcId1Val = $('#gcIdSel').val()
            };

            var goodsNameSelTxt = $('#goodsNameSel').val();
            var goodsCommonIdStr,goodsSerialStr,goodsNameStr
            if ($('#goodsNameSel option:selected').index() != 0) {
                if (goodsNameSelTxt == '商品名称') {
                    goodsNameStr = $('#inputStr').val()
                }
                if (goodsNameSelTxt == '平台货号') {
                    goodsCommonIdStr = $('#inputStr').val()
                }
                if (goodsNameSelTxt == '商品货号') {
                    goodsSerialStr = $('#inputStr').val()
                };
            } else {
                // layer.msg('sss')
            }
            data = {
                'goodsState': 10,
                'storeId': 1,
                'goodsCommonId': goodsCommonIdStr,
                'goodsSerial': goodsSerialStr,
                'goodsName': goodsNameStr,
                'gcId1': gcId1Val,
                'page': page,
                'pageSize': pagesize
            };
            data.page = 1;
            ajax(
                pageUrls,
                data,
                pageNumList,
                'post',
                'json'
            )
        }

        function OpendList(res) {
            console.log(res);
            var data = res.data.list;
            var html = '';
            $('#productList tbody').empty();

            for (i in data) {
                html += '<tr>' +
                    '<td class="text-nowrap">' +
                    '<input type="checkbox" id="" class="comCkeckbox" value="' + data[i].goodsId + '" aria-label="...">' +
                    '<div class="pull-left" style="margin-left:10px;margin-right:10px;">'
                if (data[i].goodsImage == null) {
                    html += '<img src="../image/comm.png" class="img-responsive img-thumbnail" alt="商品图片" width="100">'
                } else {
                    if (data[i].storeId == 7) {
                        html += '<img src="' + data[i].goodsImage + '" class="img-responsive img-thumbnail" alt=" " width="100">'
                    } else {
                        html += '<img src="http://axyhpic.oss-cn-zhangjiakou.aliyuncs.com/' + data[i].goodsImage + '" class="img-responsive img-thumbnail" alt=" " width="100">'
                        // var imgUrl = data[i].goodsImage;
                        // var index = imgUrl.lastIndexOf(',')
                        // if (imgUrl.lastIndexOf(',') > 0) {
                        //     console.log(imgUrl.substr(0, index));
                        //     html += '<img src="http://axyhpic.oss-cn-zhangjiakou.aliyuncs.com/' + imgUrl.substr(0, index) + '" class="img-responsive img-thumbnail" alt=" " width="50">'
                        // } else {
                        //     html += '<img src="http://axyhpic.oss-cn-zhangjiakou.aliyuncs.com/' + data[i].goodsImage + '" class="img-responsive img-thumbnail" alt=" " width="50">'
                        // }
                    }
                }

                html += '</div><div class="pull-left">'
                var str = data[i].goodsName;
                if (data[i].goodsName.length > 40) {
                    str = str.substr(0, 40)
                    html += '<p class="text-success"><a href="./goods_particulars.html?id='+data[i].goodsId+'" target="_blank">' + str + '</a>...</p>'
                } else {
                    html += '<p class="text-success"><a href="./goods_particulars.html?id='+data[i].goodsId+'" target="_blank">' + str + '</a></p>'
                }

                // html += '<p>订单编号：<span class="text-danger">7238497238947</span></p>'
                // +'<p>退款编号：<span>37489237498237498</span></p>'
                html += '</div>' +
                    '</td>' +
                    '<td class="text-center"><button class="btn btn-primary btn-sm btnSingleTs" data-gId="' + data[i].goodsId + '">上架</button></td>' +
                    '<td class="text-center">¥' + data[i].goodsPrice + '</td>' +
                    '<td class="text-center">' + data[i].goodsStorage + '</td>' +
                    '<td class="text-center">'
                if (data[i].storeId == 7) {
                    html += '<a class="btn btn-primary btn-sm" href="#" disabled>' +
                        '<span class="glyphicon glyphicon-edit" aria-hidden="true"></span>&nbsp;&nbsp;编辑' +
                        '</a>&nbsp;&nbsp;'
                } else {
                    html += '<a class="btn btn-primary btn-sm" href="./com_release.html?id=' + data[i].goodsId + '">' +
                        '<span class="glyphicon glyphicon-edit" aria-hidden="true"></span>&nbsp;&nbsp;编辑' +
                        '</a>&nbsp;&nbsp;'
                }
                html += '<button type="button" class="btn btn-primary btn-sm btnSingleDel" aria-label="Left Align" data-gId="' + data[i].goodsId + '">' +
                    '<span class="glyphicon glyphicon-trash" aria-hidden="true"></span>&nbsp;&nbsp;删除' +
                    '</button>' +
                    '</td>' +
                    '</tr>'
            }
            $('#productList tbody').append(html);
            $('input').iCheck({
                checkboxClass: 'icheckbox_flat-red pull-left',
                radioClass: 'iradio_flat-red pull-left'
            });
            $('.deleteCtrl').on('ifChecked', function() {
                $('.comCkeckbox').iCheck('check');
                $('.deleteCtrl').iCheck('check');
            });
            $('.deleteCtrl').on('ifUnchecked', function() {
                $('.comCkeckbox').iCheck('uncheck');
                $('.deleteCtrl').iCheck('uncheck');
            });


            var totalCheckBox = $('.comCkeckbox').length;
            // console.log('sfsdf:'+totalCheckBox);
            $('.comCkeckbox').on('ifChecked', function() {
                var curCheckBoxLen = $('.comCkeckbox').parents('.icheckbox_flat-red.checked').length + 1;
                // console.log(curCheckBoxLen);
                if (curCheckBoxLen == totalCheckBox) {
                    $('.deleteCtrl').parents('.icheckbox_flat-red').addClass('checked');
                }
            });

            $('.comCkeckbox').on('ifUnchecked', function() {
                var curCheckBoxLen = $('.comCkeckbox').parents('.icheckbox_flat-red.checked').length - 1;
                // console.log(curCheckBoxLen);
                if (curCheckBoxLen < totalCheckBox) {
                    $('.deleteCtrl').parents('.icheckbox_flat-red').removeClass('checked');
                }
            });

            $('.btnSingleDel').each(function(i) {
                $(this).click(function() {
                    chosenList = '';
                    chosenList += $(this).attr('data-gId') + ',';
                    console.log(chosenList);
                    superDelFun()
                })
            })

            $('.btnSingleTs').each(function(i) {
                $(this).click(function() {
                    chosenList += $(this).attr('data-gId') + ',';
                    console.log(chosenList);
                    tsFun()
                })
            })

            function tsFun() {
                layer.msg('确定上架？', {
                    time: 0,
                    btn: ['确定', '取消'],
                    yes: function(index) {
                        var delUrl = serverURL + '/goods/soltOutGoods';
                        data = {
                            'goodsId': chosenList,
                            'goodsState': 1
                        };
                        ajax(
                            delUrl,
                            data,
                            pagelist,
                            'post',
                            'json'
                        )
                        layer.close(index);
                    }
                });
            }
        }


        $('.btnDel').click(function() {
            chosenList = '';
            $('input.comCkeckbox:checked').each(function(i) {
                chosenList += this.value + ',';
            })
            console.log(chosenList);
            superDelFun()
        })

        function superDelFun() {
            layer.msg('确定删除？', {
                time: 0,
                btn: ['确定', '取消'],
                yes: function(index) {
                    var delUrl = serverURL + '/goods/deleteGoodsList';
                    data = {
                        'goodsId': chosenList
                    };
                    ajax(
                        delUrl,
                        data,
                        pagelist,
                        'post',
                        'json'
                    )
                    layer.close(index);
                }
            });
            $('#btnSearch').click(function() {
                // console.log($('#gcIdSel option:selected').index());
                // console.log($('#goodsNameSel').val() == '商品货号');
                if ($('#goodsNameSel').val() == '请选择搜索类型' && $('#inputStr').val() != '') {
                    layer.msg('请选择搜索类型');
                    return;
                }

                if ($('#goodsNameSel').val() == '平台货号' || $('#goodsNameSel').val() == '商品货号') {
                    var obj = $('#inputStr');
                    var val = obj.val();
                    if (val.length == 1) {
                        obj.val(val.replace(/[^0-9]/g, ''));
                    } else {
                        obj.val(val.replace(/\D/g, ''));
                    }
                    layer.msg('货号选项为纯数字');
                    return;
                }
                pageInit();
            })
        }


        searchFunc()

        function searchFunc() {
            var url = serverURL + '/store/queryStoreBindClass';
            data = {
                'storeId': 1
            }
            var cbk = function(res) {
                var data = res.data;
                $('#gcIdSel').empty();
                $('#gcIdSel').append('<option value="">请选择</option>')
                for (i in data) {
                    $('#gcIdSel').append('<option value="' + data[i].id1 + '">' + data[i].class1 + '</option>')
                }
            }
            ajax(
                url,
                data,
                cbk,
                'post',
                'json'
            )
        }

        $('#btnSearch').click(function() {
            // console.log($('#gcIdSel option:selected').index());
            // console.log($('#goodsNameSel').val() == '商品货号');
            if ($('#goodsNameSel').val() == '请选择搜索类型' && $('#inputStr').val() != '') {
                layer.msg('请选择搜索类型');
                return;
            }

            if ($('#goodsNameSel').val() == '平台货号' || $('#goodsNameSel').val() == '商品货号') {
                var obj = $('#inputStr');
                var val = obj.val();
                if (val.length == 1) {
                    obj.val(val.replace(/[^0-9]/g, ''));
                } else {
                    obj.val(val.replace(/\D/g, ''));
                }
                layer.msg('货号选项为纯数字');
                return;
            }
            pageInit();
        })
    </script>
</body>

</html>
